--use alerts set nocount on select cast(@@servername as varchar(30)) as [Server], cast(db_name() as varchar(30)) as [Database], cast(getdate()as char(20)) as [Script Created Date-Time] select cast(name as varchar(50)) as [All users in Database -- members of the public role] from sysusers where islogin = 1 order by isntuser select case when grouping(groupuid) = 1 and grouping(memberuid) = 1 then '' when grouping(groupuid) = 0 and grouping(memberuid) = 1 then cast(user_name(groupuid) as varchar(20)) when grouping(groupuid) = 0 and grouping(memberuid) = 0 then '' end as role, case when grouping(groupuid) = 1 and grouping(memberuid) = 1 then '' when grouping(groupuid) = 0 and grouping(memberuid) = 1 then '' when grouping(groupuid) = 0 and grouping(memberuid) = 0 then cast(user_name(memberuid) as varchar(30)) end as members from sysmembers group by groupuid, memberuid with rollup order by groupuid, memberuid select cast(type.name as varchar(10)) as [Type], cast(action.name as varchar(20)) as [Permission], '[' + cast(user_name(o.uid) as varchar(10)) + '].[' + cast(o.name as varchar(30)) + ']' as [Object], cast(user_name(p.uid) as varchar(30)) as [User] from sysprotects p inner join sysobjects o on p.id = o.id inner join master.dbo.spt_values type on p.protecttype = type.number inner join master.dbo.spt_values action on p.action = action.number where type.type = 'T' and action.type = 'T' and o.status > 0 order by o.type, o.name